<?php

class EntryFormForBackend extends EntryForm {
	public function configure(){
		$this->useFields(array("name", "content", "published", "datetime", "section_id", "position_x", "position_y"));

        $templateSettings=TemplateSettings::getInstance();
        $templateDirectory=$templateSettings->getDirectoryName();
        $templateFullPath=sfConfig::get('sf_plugins_dir')."/bertaTwigPlugin/templates/{$templateDirectory}";
        $yaml=sfYaml::load("{$templateFullPath}/entry-settings.yml");

        FormYamlConfig::configFormFromYaml($this, $yaml);

        $tagsString="";
        $tags=$this->getObject()->getTags();
        if (is_array($tags) && sizeof($tags)>0){
            $tagsString=implode(", ", $tags);
        }
		$this->setWidget("tags", new sfWidgetFormInputText(
			array("default" => $tagsString))
		);

		$this->setWidget("section_id",	new sfWidgetFormInputHidden());

		$this->setValidator("tags", new sfValidatorString(array('max_length' => 100, 'required' => false)));
	}

	public function save($con = null){
		/* @var $entry Entry */

		$entry=parent::save($con);
		if ($this->getValue("tags")!=""){
			$entry->setTags($this->getValue("tags"));
		}
		return $entry;
	}

	public function updateSectionIdColumn($value){
		if (empty($value)){
			return false;
		}else{
			return $value;
		}
	}


}
